﻿@model ZDSoft.UPMS.Model.SystemPart.User
@{
    Layout = null;
     <div id="divztree" style="display:none">@ViewBag.ztreea</div>
    <div id="divrole" style="display:none">@ViewBag.role</div>
    <div id="divroles" style="display:none">@ViewBag.temp</div>
}

<h2>修改用户信息</h2>
 
    <link href="../../Content/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/PageCreater/Css/Style.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.ztree.core-3.5.js" type="text/javascript"></script>
    <script src="../../Scripts/PageCreater/Scripts/PageCreater.js" type="text/javascript"></script>
    <link href="../../Content/tab/css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/zTree/js/jquery.ztree.excheck-3.5.js" type="text/javascript"></script>

<script type="text/javascript">
    var setting = {
        edit: {
            enable: true,
            showRemoveBtn: false,
            showRenameBtn: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: zTreeOnClick
        }
    };
    $(document).ready(function () {
        var date = $("#divztree").text();
        var zNodes = eval("(" + date + ")");
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        $("#treeDemo").css("border", "0").css("height", "170").css("background-color", "#ffffff");
        var zn = $("#divrole").text();
        var zNodessss = eval("(" + zn + ")");
        $.fn.zTree.init($("#treeDemo1"), setting1, zNodessss);
        $("#treeDemo1").css("border", "0").css("height", "170").css("background-color", "#ffffff");
        setCheck();
        setdisabled();
    })


    function zTreeOnClick(event, treeId, treeNode) {
        $("#inputselected").val(treeNode.name);
        $("#inputselected").attr("name", treeNode.id);
        $("#jigou").val(treeNode.id);
    }

    var setting1 = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }, 
        callback: {
            onCheck: zTreeOnCheck
        }
    };
    function setCheck() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo1"),
			   type = { "Y": "", "N": "" };
        zTree.setting.check.chkboxType = type;
    }
    function clicks() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
        var nodes = treeObj.getCheckedNodes(true);
        var roles = "";
        for (var i = 0; i < nodes.length; i++) {
            roles += nodes[i].id + ",";
        }
        $("#getroles").val(roles);

        var re = /^[A-Za-z0-9]+$/;
        if (!re.test($("#Account").val())) {
            alert("不能输入汉字和特殊字符");
            $("#Account").focus();
            tuichu();
        }

        var rer = new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5]+$");
        if (!rer.test($("#Name").val())) {
            alert("只能输入纯中文名字或纯英文名");
            $("#Name").focus();
            tuichu();
        }

        if ($("#getroles").val() == "") {
            alert("请选择角色");
            tuichu();
        }

        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getNodesByParamFuzzy("name", $("#inputselected").val(), null);
        if (nodes[0].id != $("#inputselected").attr("name")) {
            alert("请选择机构");
            tuichu();
        }
    }
    function tuichu() {
        document.getElementsByTagName("body")[0].getElementsByTagName("form")[0].onsubmit = function () {
            return false;
        }
    }

    function bindjuese() {
        var zn = $("#divroles").text();
        var zNodessss = eval("(" + zn + ")");
        $.fn.zTree.init($("#treeDemo1"), setting1, zNodessss);
        $("#treeDemo1").css("border", "0");
        setCheck();
    }

    function setdisabled() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
        var nodes = treeObj.getCheckedNodes(true);
        if (nodes[0].name == "学生") {
            var nodess = treeObj.getCheckedNodes(false);
            for (var i = 0; i < nodess.length; i++) {
                treeObj.setChkDisabled(nodess[i], true);
            }
        }
        else {
            var node = treeObj.getNodeByParam("name", "学生", null);
            treeObj.setChkDisabled(node, true);
        }
    }

    function zTreeOnCheck(event, treeId, treeNode) {
        if (treeNode.name == "学生") {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
            var nodes = treeObj.getCheckedNodes(false);
            if (treeNode.checked) {
                var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
                var nodes1 = treeObj.getCheckedNodes(false);
                for (var i = 0; i < nodes1.length; i++) {
                    treeObj.setChkDisabled(nodes1[i], true);
                }
            }
            else {
                bindjuese();
            }
        }
        else {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
            var node = treeObj.getNodeByParam("name", "学生", null);
            treeObj.setChkDisabled(node, true);
        }
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
        var nodes = treeObj.getCheckedNodes(true);
        if (nodes == "") {
            bindjuese();
        };
    };
</script>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
       <legend>用户信息修改</legend>
         @{
              var organ = TempData["organ"] as ZDSoft.UPMS.Model.BusinessPart.Organization;
          }
         <div style="float:left">
            <div class="editor-label">
               用户名
            </div>
            <div class="editor-field">
               @Html.EditorFor(model => model.Account)
               @Html.ValidationMessageFor(model => model.Account)
            </div>

            <div class="editor-label">
               姓名
            </div>
            <div class="editor-field">
               @Html.EditorFor(model => model.Name)
               @Html.ValidationMessageFor(model => model.Name)
            </div>
            <div class="editor-field">
              状态&nbsp;
               @Html.CheckBoxFor(model=>model.IsActive)
               @Html.ValidationMessageFor(model=>model.IsActive)
            </div>
            <p>
               机构<br />
               @if (organ != null)
               {
                  <input type="text" id="inputselected" readonly="readonly"  value="@organ.Name" name="@organ.ID" />
               }
               else
               { 
                  <input type="text" id="inputselected" value="" readonly="readonly"  name="" />
               }
            </p>
            @Html.HiddenFor(model => model.ID)
            @Html.Hidden("getroles")
            @Html.Hidden("jigou")
         </div>
         <div style="float:left">
              <span>机构修改</span>
              <ul id="treeDemo" class="ztree" style="overflow: auto; height:300px"></ul>
         </div>
         <div style="float:left">
              <span>角色修改</span>
              <ul id="treeDemo1" class="ztree" style="overflow: auto; height:300px"></ul>
         </div>
     
    </fieldset>
    
       <center><input type="submit"  class="btn3" value="修改" id="fd" onclick="clicks();" />@Html.ActionLink("返回首页", "Index")</center> 
    
}

